package com.wbihua.grpc.demo.condition;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

@Slf4j
public class WindowCondtion implements Condition {

    private final String OS_NAME = "os.name";
    private final String OS_NAME_TAG = "Windows";

    @Override
    public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
        Environment env = conditionContext.getEnvironment();
        String os = env.getProperty(OS_NAME);
        log.info("os:{}", os);

        if(os.contains(OS_NAME_TAG)){
            return true;
        }
        return false;
    }
}
